extends TextureButton


var data = null

const icons = [
	"res://tool/assets/map/interactive_0.png",
	"res://tool/assets/map/interactive_1.png",
	"res://tool/assets/map/interactive_2.png",
]

func _ready():
	pass 



func set_data(data):
	self.data = data
	rect_position = Vector2(data["x"]+50000, data["y"]+50000)
	
	self.texture_normal = load(icons[data["type"]])
	self.texture_pressed = self.texture_normal
	self.texture_hover = self.texture_normal
	self.texture_disabled = self.texture_normal
	self.texture_focused = self.texture_normal

	
	$Label.text = "障碍物" 


func _on_del_ok(data):
	DataSource.delete_data_by_id(DataSource.map_interactive, data["id"])
	
	var map_view = MainTool.getUILayer().get_ui("MapView")
	map_view.entity_update()
	


func _on_gui_input(event):
	if event is InputEventMouseButton:  
		if event.button_index == BUTTON_RIGHT and event.pressed:  
			# 鼠标右键被按下，确认删除
			MainTool.confirm("你是否确认删除该障碍物", self, "_on_del_ok", null, data)


func _on_MapInteractive_button_up():
	var ui = MainTool.getUILayer().add_ui("res://tool/page/map/mapView/modal/MapInteractiveModal.tscn", 0, true)
	ui.set_edit_data(data)
